package com.hoshiicloud.payment.rabbitmq;

import com.hoshiicloud.common.utils.EncryptionUtil;
import com.hoshiicloud.payment.config.RsaConfig;
import java.util.Base64;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.stereotype.Component;

/**
 * @program: hoshiicloud
 * @description: 支付回调消费者
 * @author: Mr.wu
 * @create: 2019-06-01 15:15
 **/
@Component
@Slf4j
public class PaymentCallbackReceiver {

    //@RabbitListener(queues = RabbitMQConfig.PAY_CALLBACK_QUEUE)
    //@RabbitHandler
    public void payCallBackprocess(Message message) throws Exception {
        try {
            log.info("接受回调消息" + message.toString());
            //获取请求体转换
            String body = new String(message.getBody());
            log.info("body:" + body);
            System.out.println(body);
            String json = new String(Base64.getMimeDecoder().decode(body.replace("\r\n", "")));
            Map<String, String> data = EncryptionUtil
                    .decryptData(json, RsaConfig.getClientPublicKey(),
                            RsaConfig.getServerPrivateKey());
            if (data == null) {
                //验签失败
            }
            log.info("明文数据:" + data.toString());
            //业务处理
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.toString());
            //throw e;
        }

    }
}
